import functools


class Solution:
    def removeCoveredIntervals(self, intervals: list) -> int:
        def cmp(a, b):
            if a[0] < b[0]:
                return -1
            elif a[0] > b[0]:
                return 1
            else:
                if a[1] > b[1]:
                    return -1
                else:
                    return 1
        intervals.sort(key=functools.cmp_to_key(cmp))
        d = 0
        last = intervals[0]
        for i in range(1, len(intervals)):
            cur = intervals[i]
            if cur[0] >= last[0] and cur[1] <= last[1]:
                d += 1
                continue
            last = cur
        return len(intervals) - d
